/**
 * 报表设计公司(2011)
 */
package com.reportgear.designer.pane.style;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.TexturePaint;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JToggleButton;
import javax.swing.SpringLayout;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;

import com.reportgear.core.swing.pane.base.JBasePane;
import com.reportgear.designer.ui.base.ColorSelectionPane;
import com.reportgear.designer.ui.base.ImageFileChooser;
import com.reportgear.designer.ui.base.JNumberField;
import com.reportgear.report.core.api.compare.ComparatorUtils;
import com.reportgear.report.core.background.ColorBackground;
import com.reportgear.report.core.background.GradientBackground;
import com.reportgear.report.core.background.ImageBackground;
import com.reportgear.report.core.background.ImagePreviewPane;
import com.reportgear.report.core.background.PatternBackground;
import com.reportgear.report.core.background.TextureBackground;
import com.reportgear.report.model.cell.style.background.Background;
import com.reportgear.report.view.JWorksheet;
import com.reportgear.report.view.grid.util.GraphHelper;

/**
 * @version 1.0 2011-3-24
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ANNCSR 2.0
 */
public class BackgroundPane extends JBasePane implements ICellStyle {

	private JTabbedPane tabbedPane = null;
	private NullBackgroundPane nullBackgroundPane = null;
	private ColorBackgroundPane colorBackgroundPane = null;
	private TextureBackgroundPane textureBackgroundPane = null;
	private PatternBackgroundPane patternBackgroundPane = null;
	private ImageBackgroundPane imageBackgroundPane = null;
	private GradientBackgroundPane gradientBackgroundPane = null;
	private ChangeListener backgroundChangeListener = new ChangeListener() {

		public void stateChanged(ChangeEvent paramChangeEvent) {
			BackgroundPane.this.previewPane.setBackgroundObject(BackgroundPane.this.update());
			BackgroundPane.this.previewPane.repaint();
		}
	};
	private BackgroundPreviewLabel previewPane = null;
	static TexturePaint[] EmbedTexturePaintArray = { TextureBackground.NewsprintTexturePaint,
			TextureBackground.RecycledPaperTexturePaint, TextureBackground.ParchmentTexturePaint,
			TextureBackground.StationeryTexturePaint, TextureBackground.GreenMarbleTexturePaint,
			TextureBackground.WhiteMarbleTexturePaint, TextureBackground.BrownMarbleTexturePaint,
			TextureBackground.GraniteTexturePaint, TextureBackground.BlueTissuePaperTexturePaint,
			TextureBackground.PinkTissuePaperTexturePaint, TextureBackground.PurpleMeshTexturePaint,
			TextureBackground.BouquetTexturePaint, TextureBackground.PapyrusTexturePaint,
			TextureBackground.CanvasTexturePaint, TextureBackground.DenimTexturePaint,
			TextureBackground.WovenMatTexturePaint, TextureBackground.WaterDropletsTexturePaint,
			TextureBackground.PaperBagTexturePaint, TextureBackground.FishFossilTexturePaint,
			TextureBackground.SandTexturePaint, TextureBackground.CorkTexturePaint,
			TextureBackground.WalnutTexturePaint, TextureBackground.OakTexturePaint,
			TextureBackground.MediumWoodTexturePaint };
	static String[] EmbedTexturePaintDesArray = { "BackgroundTexture-Newsprint", "BackgroundTexture-RecycledPaper",
			"BackgroundTexture-Parchment", "BackgroundTexture-Stationery", "BackgroundTexture-GreenMarble",
			"BackgroundTexture-WhiteMarble", "BackgroundTexture-BrownMarble", "BackgroundTexture-Granite",
			"BackgroundTexture-BlueTissuePaper", "BackgroundTexture-PinkTissuePaper", "BackgroundTexture-PurpleMesh",
			"BackgroundTexture-Bouquet", "BackgroundTexture-Papyrus", "BackgroundTexture-Canvas",
			"BackgroundTexture-Denim", "BackgroundTexture-WovenMat", "BackgroundTexture-WaterDroplets",
			"BackgroundTexture-PaperBag", "BackgroundTexture-FishFossil", "BackgroundTexture-Sand",
			"BackgroundTexture-Cork", "BackgroundTexture-Walnut", "BackgroundTexture-Oak",
			"BackgroundTexture-MediumWood" };

	public BackgroundPane() {
		initComponents();
	}

	private void initComponents() {
		setLayout(new BorderLayout(0, 2));
		JPanel localJPanel = new JPanel();
		add(localJPanel, "Center");
		localJPanel.setLayout(new BorderLayout());
		localJPanel.setBorder(BorderFactory.createTitledBorder("预览"));
		this.previewPane = new BackgroundPreviewLabel();
		this.previewPane.addBackgroundChangeListener(new ChangeListener() {

			public void stateChanged(ChangeEvent paramChangeEvent) {
				BackgroundPane.this.fireStateChanged();
			}
		});
		localJPanel.add(this.previewPane, "Center");
		this.tabbedPane = new JTabbedPane();
		add(this.tabbedPane, "South");
		this.tabbedPane.addTab("没有背景", new JPanel());
		this.tabbedPane.addTab("颜色", new JPanel());
		this.tabbedPane.addTab("纹理", new JPanel());
		this.tabbedPane.addTab("图案", new JPanel());
		this.tabbedPane.addTab("图片", new JPanel());
		this.tabbedPane.addChangeListener(this.backgroundChangeListener);
		this.tabbedPane.setPreferredSize(new Dimension(200, 210));
	}

	public void addChangeListener(ChangeListener paramChangeListener) {
	}

	public void fireStateChanged() {
		// Object[] arrayOfObject = this.eventChangeList.getListenerList();
		// ChangeEvent localChangeEvent = null;
		// for (int i = arrayOfObject.length - 2; i >= 0; i -= 2) {
		// if (arrayOfObject[i] != ChangeListener.class) {
		// continue;
		// }
		// if (localChangeEvent == null) {
		// localChangeEvent = new ChangeEvent(this);
		// }
		// ((ChangeListener) arrayOfObject[(i +
		// 1)]).stateChanged(localChangeEvent);
		// }
	}

	private NullBackgroundPane getNullBackgroundPane() {
		if (this.nullBackgroundPane == null) {
			this.nullBackgroundPane = new NullBackgroundPane();
			this.nullBackgroundPane.addChangeListener(this.backgroundChangeListener);
		}
		return this.nullBackgroundPane;
	}

	private ColorBackgroundPane getColorBackgroundPane() {
		if (this.colorBackgroundPane == null) {
			this.colorBackgroundPane = new ColorBackgroundPane();
			this.colorBackgroundPane.addChangeListener(this.backgroundChangeListener);
		}
		return this.colorBackgroundPane;
	}

	private TextureBackgroundPane getTextureBackgroundPane() {
		if (this.textureBackgroundPane == null) {
			this.textureBackgroundPane = new TextureBackgroundPane();
			this.textureBackgroundPane.addChangeListener(this.backgroundChangeListener);
		}
		return this.textureBackgroundPane;
	}

	private PatternBackgroundPane getPatternBackgroundPane() {
		if (this.patternBackgroundPane == null) {
			this.patternBackgroundPane = new PatternBackgroundPane();
			this.patternBackgroundPane.addChangeListener(this.backgroundChangeListener);
		}
		return this.patternBackgroundPane;
	}

	private ImageBackgroundPane getImageBackgroundPane() {
		if (this.imageBackgroundPane == null) {
			this.imageBackgroundPane = new ImageBackgroundPane();
			this.imageBackgroundPane.addChangeListener(this.backgroundChangeListener);
		}
		return this.imageBackgroundPane;
	}

	private GradientBackgroundPane getGradientBackgroundPane() {
		if (this.gradientBackgroundPane == null) {
			this.gradientBackgroundPane = new GradientBackgroundPane();
			this.gradientBackgroundPane.addChangeListener(this.backgroundChangeListener);
		}
		return this.gradientBackgroundPane;
	}

	public void populate(Background paramBackground) {
		if (paramBackground == null) {
			this.tabbedPane.setComponentAt(0, getNullBackgroundPane());
			this.tabbedPane.setSelectedIndex(0);
			this.nullBackgroundPane.populate(paramBackground);
		} else if (paramBackground instanceof ColorBackground) {
			this.tabbedPane.setComponentAt(1, getColorBackgroundPane());
			this.tabbedPane.setSelectedIndex(1);
			this.colorBackgroundPane.populate(paramBackground);
		} else if (paramBackground instanceof TextureBackground) {
			this.tabbedPane.setComponentAt(2, getTextureBackgroundPane());
			this.tabbedPane.setSelectedIndex(2);
			this.textureBackgroundPane.populate(paramBackground);
		} else if (paramBackground instanceof PatternBackground) {
			this.tabbedPane.setComponentAt(3, getPatternBackgroundPane());
			this.tabbedPane.setSelectedIndex(3);
			this.patternBackgroundPane.populate(paramBackground);
		} else if (paramBackground instanceof ImageBackground) {
			this.tabbedPane.setComponentAt(4, getImageBackgroundPane());
			this.tabbedPane.setSelectedIndex(4);
			this.imageBackgroundPane.populate(paramBackground);
		} else if (paramBackground instanceof GradientBackground) {
			this.tabbedPane.setComponentAt(5, getGradientBackgroundPane());
			this.tabbedPane.setSelectedIndex(5);
			this.gradientBackgroundPane.populate(paramBackground);
		}
		this.tabbedPane.doLayout();
		this.tabbedPane.validate();
	}

	public Background update() {
		try {
			Object localObject = this.tabbedPane.getSelectedComponent();
			if (localObject.getClass() == JPanel.class) {
				int i = this.tabbedPane.getSelectedIndex();
				if (i == 0) {
					localObject = getNullBackgroundPane();
				} else if (i == 1) {
					localObject = getColorBackgroundPane();
				} else if (i == 2) {
					localObject = getTextureBackgroundPane();
				} else if (i == 3) {
					localObject = getPatternBackgroundPane();
				} else if (i == 4) {
					localObject = getImageBackgroundPane();
				} else if (i == 5) {
					localObject = getGradientBackgroundPane();
				}
				this.tabbedPane.setComponentAt(i, (Component) localObject);
			}
			if (localObject instanceof BackgroundSettingPane) {
				return ((BackgroundSettingPane) localObject).update();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return null;
	}

	public void populateCellStyle(JWorksheet workSheet) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void updateCellStyle(JWorksheet workSheet) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	class GradientBackgroundPane extends BackgroundPane.BackgroundSettingPane {

		ChangeListener changeListener = null;
		String[] scrollNames = { "X1", "Y1", "X2", "Y2" };
		int[] scrollValues = new int[this.scrollNames.length];
		Color[] colors = { Color.black, Color.white };
		JScrollBar[] scrolls = new JScrollBar[this.scrollNames.length];
		ColorSelectionPane[] colorPanes = new ColorSelectionPane[this.colors.length];

		public void addChangeListener(ChangeListener paramChangeListener) {
			this.changeListener = paramChangeListener;
		}

		private void fireStateChanged() {
			if (this.changeListener == null) {
				return;
			}
			ChangeEvent localChangeEvent = new ChangeEvent(this);
			this.changeListener.stateChanged(localChangeEvent);
		}

		GradientBackgroundPane() {
			super();
			initComponents();
		}

		protected void initComponents() {
			setLayout(new BorderLayout());
			JPanel localJPanel1 = new JPanel();
			add(localJPanel1, "West");
			localJPanel1.setBorder(BorderFactory.createTitledBorder("Color"));
			localJPanel1.setPreferredSize(new Dimension(150, 0));
			JPanel localJPanel2 = new JPanel();
			add(localJPanel2, "Center");
			localJPanel2.setBorder(BorderFactory.createTitledBorder("阴影样式"));
			localJPanel1.setLayout(new BorderLayout());
			JPanel localJPanel3 = new JPanel();
			JPanel localJPanel4 = new JPanel();
			JPanel localJPanel5 = new JPanel();
			JPanel localJPanel6 = new JPanel();
			JPanel localJPanel7 = new JPanel();
			localJPanel1.add(localJPanel3, "North");
			localJPanel1.add(localJPanel7, "Center");
			localJPanel5.setLayout(new CardLayout());
			localJPanel5.add("one", localJPanel6);
			localJPanel5.add("two", localJPanel4);
			JRadioButton[] arrayOfJRadioButton1 = new JRadioButton[2];
			localJPanel3.setLayout(new GridLayout(arrayOfJRadioButton1.length, 1));
			ButtonGroup localButtonGroup1 = new ButtonGroup();
			arrayOfJRadioButton1[0] = new JRadioButton("一种颜色", true);
			// arrayOfJRadioButton1[0].addActionListener(new BackgroundPane.9
			// (this,
			// localJPanel5)
			// );
			localJPanel3.add(arrayOfJRadioButton1[0]);
			localButtonGroup1.add(arrayOfJRadioButton1[0]);
			arrayOfJRadioButton1[1] = new JRadioButton("两种颜色");
			// arrayOfJRadioButton1[1].addActionListener(new BackgroundPane.10
			// (this,
			// localJPanel5)
			// );
			localJPanel3.add(arrayOfJRadioButton1[1]);
			localButtonGroup1.add(arrayOfJRadioButton1[1]);
			for (int i = 0; i < this.scrolls.length; ++i) {
				this.scrolls[i] = new JScrollBar(0);
				this.scrolls[i].setToolTipText(this.scrollNames[i]);
				this.scrolls[i].setMaximum(100);
				this.scrolls[i].setMinimum(0);
				int j = i;
			}
			for (int i = 0; i < this.colorPanes.length; ++i) {
				this.colorPanes[i] = new ColorSelectionPane(80);
			}
			localJPanel4.setLayout(new BorderLayout());
			localJPanel4.add(this.colorPanes[1], "North");
			localJPanel6.setLayout(new BorderLayout());
			JScrollBar localJScrollBar = new JScrollBar(0);
			localJScrollBar.setMaximum(255);
			localJPanel6.add(localJScrollBar, "North");
			localJPanel7.setLayout(new BorderLayout());
			localJPanel7.add(this.colorPanes[0], "North");
			localJPanel7.add(localJPanel5, "Center");
			String[] arrayOfString = { "水平", "垂直", "斜向上", "斜向下", "水平（密集）", "垂直（密集）", "斜向上（密集）", "斜向下（密集）", "斜向上（30度）",
					"斜向下（30度）", "斜向上（30度，密集）", "斜向下（30度，密集）" };
			JRadioButton[] arrayOfJRadioButton2 = new JRadioButton[arrayOfString.length];
			localJPanel2.setLayout(new GridLayout(arrayOfJRadioButton2.length / 2, 2));
			ButtonGroup localButtonGroup2 = new ButtonGroup();
			for (int k = 0; k < arrayOfJRadioButton2.length; ++k) {
				arrayOfJRadioButton2[k] = new JRadioButton(arrayOfString[k]);
				int l = k;
				// arrayOfJRadioButton2[k].addActionListener(new
				// BackgroundPane.14
				// (this,
				// l)
				// );
				localJPanel2.add(arrayOfJRadioButton2[k]);
				localButtonGroup2.add(arrayOfJRadioButton2[k]);
			}
			arrayOfJRadioButton2[0].setSelected(true);
			setScrollValues(new int[] { 80, 80, 80, 0 });
			this.colorPanes[0].setColor(Color.BLACK);
			this.colorPanes[1].setColor(Color.WHITE);
		}

		private void setScrollValues(int[] paramArrayOfInt) {
			for (int i = 0; i < this.scrolls.length; ++i) {
				this.scrolls[i].setValue(paramArrayOfInt[i]);
			}
		}

		public void populate(Background paramBackground) {
			if (!(paramBackground instanceof GradientBackground)) {
				return;
			}
			GradientBackground localGradientBackground = (GradientBackground) paramBackground;
			GradientPaint localGradientPaint = localGradientBackground.getGradientPaint();
			this.scrolls[0].setValue((int) localGradientPaint.getPoint1().getX());
			this.scrolls[1].setValue((int) localGradientPaint.getPoint1().getY());
			this.scrolls[2].setValue((int) localGradientPaint.getPoint2().getX());
			this.scrolls[3].setValue((int) localGradientPaint.getPoint2().getY());
			this.colorPanes[0].setColor(localGradientPaint.getColor1());
			this.colorPanes[1].setColor(localGradientPaint.getColor2());
		}

		public Background update() throws Exception {
			GradientPaint localGradientPaint = new GradientPaint(this.scrollValues[0], this.scrollValues[1],
					this.colorPanes[0].getColor(), this.scrollValues[2], this.scrollValues[3], this.colorPanes[1]
							.getColor(), true);
			return new GradientBackground(localGradientPaint);
		}
	}

	class ImageBackgroundPane extends BackgroundPane.BackgroundSettingPane {

		private ImagePreviewPane previewPane = null;
		private JRadioButton defaultRadioButton = null;
		private JRadioButton centerRadioButton = null;
		private JRadioButton extendRadioButton = null;
		private JRadioButton tiledRadioButton = null;
		private ChangeListener changeListener = null;
		private ImageFileChooser imageFileChooser = null;
		private JLabel imageSizeLabel = new JLabel();
		private JCheckBox specifySizeCheckBox;
		private JPanel southImageSizePane;
		private JNumberField widthNumberField;
		private JNumberField heightNumberField;

		public ImageBackgroundPane() {
			super();
			setLayout(new BorderLayout(0, 0));
			JPanel localJPanel1 = new JPanel();
			add(localJPanel1, "Center");
			localJPanel1.setLayout(new BorderLayout(0, 0));
			JPanel localJPanel2 = new JPanel();
			localJPanel1.add(localJPanel2, "Center");
			localJPanel2.setBorder(BorderFactory.createTitledBorder("Preview"));
			localJPanel2.setLayout(new BorderLayout());
			this.previewPane = new ImagePreviewPane();
			localJPanel2.add(new JScrollPane(this.previewPane));
			// this.previewPane.addChangeListener(this.imageSizeChangeListener);
			JPanel localJPanel3 = new JPanel();
			localJPanel1.add(localJPanel3, "East");
			localJPanel3.setLayout(new BorderLayout());
			localJPanel3.setBorder(BorderFactory.createEmptyBorder(8, 2, 4, 0));
			JButton localJButton = new JButton("Image-Select_Picture");
			localJPanel3.add(localJButton, "North");
			localJButton.setMnemonic('S');
			// localJButton.addActionListener(this.selectPicturActionListener);
			this.imageSizeLabel.setHorizontalAlignment(0);
			localJPanel3.add(this.imageSizeLabel, "Center");
			JPanel localJPanel4 = new JPanel();
			localJPanel3.add(localJPanel4, "South");
			localJPanel4.setLayout(new BorderLayout(0, 4));
			this.specifySizeCheckBox = new JCheckBox("Image-Specified_Size", false);
			localJPanel4.add(this.specifySizeCheckBox, "North");
			// this.specifySizeCheckBox.addActionListener(new BackgroundPane.4
			// (this)
			// );
			this.southImageSizePane = new JPanel();
			localJPanel4.add(this.southImageSizePane, "Center");
			this.southImageSizePane.setLayout(new SpringLayout());
			this.widthNumberField = new JNumberField();
			this.widthNumberField.setColumns(4);
			// this.widthNumberField.addKeyListener(this.widthHeightKeyListener);
			this.southImageSizePane.add(new JLabel("Width" + ":"));
			this.southImageSizePane.add(this.widthNumberField);
			this.widthNumberField.setEnabled(false);
			this.heightNumberField = new JNumberField();
			this.heightNumberField.setColumns(4);
			// this.heightNumberField.addKeyListener(this.widthHeightKeyListener);
			this.southImageSizePane.add(new JLabel("Height" + ":"));
			this.southImageSizePane.add(this.heightNumberField);
			this.heightNumberField.setEnabled(false);
			// if (this.southImageSizePane.getLayout() instanceof SpringLayout)
			// {
			// localObject1 = (SpringLayout)
			// this.southImageSizePane.getLayout();
			// localObject2 = Spring.constant(6);
			// for (int i = 0; i < 2; ++i) {
			// Spring localSpring2 = Spring.constant(0);
			// for (int k = 0; k < 2; ++k) {
			// localSpring2 = Spring.max(localSpring2, ((SpringLayout)
			// localObject1).getConstraints(this.southImageSizePane.getComponent(k
			// * 2 + i)).getWidth());
			// }
			// for (k = 0; k < 2; ++k) {
			// SpringLayout.Constraints localConstraints2 = ((SpringLayout)
			// localObject1).getConstraints(this.southImageSizePane.getComponent(k
			// * 2 + i));
			// localConstraints2.setX((Spring) localObject2);
			// localConstraints2.setWidth(localSpring2);
			// }
			// localObject2 = Spring.sum((Spring) localObject2,
			// Spring.sum(localSpring2, Spring.constant(2)));
			// }
			// Spring localSpring1 = Spring.constant(6);
			// for (int j = 0; j < 2; ++j) {
			// Spring localSpring3 = Spring.constant(0);
			// for (int l = 0; l < 2; ++l) {
			// localSpring3 = Spring.max(localSpring3, ((SpringLayout)
			// localObject1).getConstraints(this.southImageSizePane.getComponent(j
			// * 2 + l)).getHeight());
			// }
			// for (l = 0; l < 2; ++l) {
			// SpringLayout.Constraints localConstraints3 = ((SpringLayout)
			// localObject1).getConstraints(this.southImageSizePane.getComponent(j
			// * 2 + l));
			// localConstraints3.setY(localSpring1);
			// localConstraints3.setHeight(localSpring3);
			// }
			// localSpring1 = Spring.sum(localSpring1, Spring.sum(localSpring3,
			// Spring.constant(2)));
			// }
			// SpringLayout.Constraints localConstraints1 = ((SpringLayout)
			// localObject1).getConstraints(this.southImageSizePane);
			// localConstraints1.setConstraint("South", localSpring1);
			// localConstraints1.setConstraint("East", (Spring) localObject2);
			// } else {
			// GUICoreUtils.setEnabled(this.southImageSizePane, false);
			// }
			Object localObject1 = new JPanel();
			add((Component) localObject1, "South");
			((JPanel) localObject1).setBorder(BorderFactory.createTitledBorder("Image-Layout"));
			((JPanel) localObject1).setLayout(new GridLayout(1, 3));
			this.defaultRadioButton = new JRadioButton("Default");
			this.tiledRadioButton = new JRadioButton("Image-Titled");
			this.centerRadioButton = new JRadioButton("Center");
			this.extendRadioButton = new JRadioButton("Image-Extend");
			this.defaultRadioButton.setMnemonic('D');
			this.tiledRadioButton.setMnemonic('T');
			this.centerRadioButton.setMnemonic('C');
			this.extendRadioButton.setMnemonic('E');
			// this.defaultRadioButton.addActionListener(this.layoutActionListener);
			// this.tiledRadioButton.addActionListener(this.layoutActionListener);
			// this.centerRadioButton.addActionListener(this.layoutActionListener);
			// this.extendRadioButton.addActionListener(this.layoutActionListener);
			this.defaultRadioButton.setHorizontalAlignment(0);
			this.tiledRadioButton.setHorizontalAlignment(0);
			this.centerRadioButton.setHorizontalAlignment(0);
			this.extendRadioButton.setHorizontalAlignment(0);
			((JPanel) localObject1).add(this.defaultRadioButton);
			((JPanel) localObject1).add(this.tiledRadioButton);
			((JPanel) localObject1).add(this.centerRadioButton);
			((JPanel) localObject1).add(this.extendRadioButton);
			Object localObject2 = new ButtonGroup();
			((ButtonGroup) localObject2).add(this.defaultRadioButton);
			((ButtonGroup) localObject2).add(this.tiledRadioButton);
			((ButtonGroup) localObject2).add(this.centerRadioButton);
			((ButtonGroup) localObject2).add(this.extendRadioButton);
			this.defaultRadioButton.setSelected(true);
			this.imageFileChooser = new ImageFileChooser();
			this.imageFileChooser.setMultiSelectionEnabled(false);
		}

		public void populate(Background paramBackground) {
			this.specifySizeCheckBox.setSelected(false);
			if (paramBackground instanceof ImageBackground) {
				ImageBackground localImageBackground = (ImageBackground) paramBackground;
				if (localImageBackground.getLayout() == 1) {
					this.centerRadioButton.setSelected(true);
				} else if (localImageBackground.getLayout() == 2) {
					this.extendRadioButton.setSelected(true);
				} else if (localImageBackground.getLayout() == 3) {
					this.defaultRadioButton.setSelected(true);
				} else {
					this.tiledRadioButton.setSelected(true);
				}
				if (localImageBackground.getImage() != null) {
					this.previewPane.setImage(localImageBackground.getImage());
					this.imageSizeLabel.setText(this.previewPane.getImage().getWidth(null) + " X "
							+ this.previewPane.getImage().getHeight(null));
				}
				this.widthNumberField.setValue(1.7976931348623157E+308D);
				this.heightNumberField.setValue(1.7976931348623157E+308D);
				if (localImageBackground.getImage() != null) {
					this.previewPane.setImage(localImageBackground.getImage());
					if ((localImageBackground.getSpecifiedImageWidth() != -1.0D)
							&& (localImageBackground.getSpecifiedImageHeight() != -1.0D)) {
						this.specifySizeCheckBox.setSelected(true);
						this.widthNumberField.setValue(localImageBackground.getSpecifiedImageWidth());
						this.heightNumberField.setValue(localImageBackground.getSpecifiedImageHeight());
					}
				}
			} else {
				this.previewPane.setImage(null);
				this.tiledRadioButton.setSelected(true);
				this.imageSizeLabel.setText("");
			}
			// if (this.specifySizeCheckBox.isSelected()) {
			// GUICoreUtils.setEnabled(this.southImageSizePane, true);
			// } else {
			// GUICoreUtils.setEnabled(this.southImageSizePane, false);
			// }
			fireChagneListener();
		}

		public Background update() throws Exception {
			ImageBackground localImageBackground = new ImageBackground(this.previewPane.getImage());
			if (this.specifySizeCheckBox.isSelected()) {
				if ((this.widthNumberField.getValue() < 0.0D)
						|| (this.widthNumberField.getValue() == 1.7976931348623157E+308D)) {
					localImageBackground.setSpecifiedImageWidth(this.previewPane.getImage().getWidth(null));
				} else {
					localImageBackground.setSpecifiedImageWidth(this.widthNumberField.getValue());
				}
				if ((this.heightNumberField.getValue() < 0.0D)
						|| (this.heightNumberField.getValue() == 1.7976931348623157E+308D)) {
					localImageBackground.setSpecifiedImageHeight(this.previewPane.getImage().getHeight(null));
				} else {
					localImageBackground.setSpecifiedImageHeight(this.heightNumberField.getValue());
				}
			} else {
				this.widthNumberField.setValue(1.7976931348623157E+308D);
				this.heightNumberField.setValue(1.7976931348623157E+308D);
			}
			if (this.tiledRadioButton.isSelected()) {
				localImageBackground.setLayout(0);
			} else if (this.centerRadioButton.isSelected()) {
				localImageBackground.setLayout(1);
			} else if (this.extendRadioButton.isSelected()) {
				localImageBackground.setLayout(2);
			} else {
				localImageBackground.setLayout(3);
			}
			return localImageBackground;
		}

		public void addChangeListener(ChangeListener paramChangeListener) {
			this.changeListener = paramChangeListener;
		}

		private void fireChagneListener() {
			if (this.changeListener == null) {
				return;
			}
			ChangeEvent localChangeEvent = new ChangeEvent(this);
			this.changeListener.stateChanged(localChangeEvent);
		}
	}

	class PatternBackgroundPane extends BackgroundPane.BackgroundSettingPane {

		private int patternIndex = 0;
		private ColorSelectionPane foregroundColorPane;
		private ColorSelectionPane backgroundColorPane;
		private PatternButton[] patternButtonArray;

		public PatternBackgroundPane() {
			super();
			initComponents();
		}

		protected void initComponents() {
			setLayout(new BorderLayout());
			setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
			JPanel localJPanel1 = new JPanel();
			add(localJPanel1, "North");
			localJPanel1.setLayout(new BoxLayout(localJPanel1, 1));
			JPanel localJPanel2 = new JPanel();
			localJPanel1.add(localJPanel2);
			localJPanel2.setLayout(new FlowLayout(1, 2, 3));
			localJPanel2.setBorder(BorderFactory.createTitledBorder("Background-Pattern"));
			JPanel localJPanel3 = new JPanel();
			localJPanel2.add(localJPanel3);
			localJPanel3.setLayout(new GridLayout(4, 12, 4, 2));
			ButtonGroup localButtonGroup = new ButtonGroup();
			this.patternButtonArray = new PatternButton[48];
			for (int i = 0; i < 48; ++i) {
				this.patternButtonArray[i] = new PatternButton(i);
				localButtonGroup.add(this.patternButtonArray[i]);
				localJPanel3.add(this.patternButtonArray[i]);
			}
			JPanel localJPanel4 = new JPanel();
			localJPanel1.add(localJPanel4);
			localJPanel4.setLayout(new FlowLayout(1, 12, 6));
			localJPanel4.setBorder(BorderFactory.createTitledBorder("Colors"));
			localJPanel4.setLayout(new BoxLayout(localJPanel4, 0));
			this.foregroundColorPane = new ColorSelectionPane(80);
			this.backgroundColorPane = new ColorSelectionPane(80);
			this.backgroundColorPane.setCanBeNull(true);
			this.foregroundColorPane.setColor(Color.lightGray);
			this.backgroundColorPane.setColor(Color.black);
			// this.foregroundColorPane.addColorChangeListener(this.colorChangeListener);
			// this.backgroundColorPane.addColorChangeListener(this.colorChangeListener);
			localJPanel4.add(Box.createHorizontalStrut(2));
			localJPanel4.add(createLabelColorPane("Foreground" + ":", this.foregroundColorPane));
			localJPanel4.add(Box.createHorizontalStrut(8));
			localJPanel4.add(createLabelColorPane("Background" + ":", this.backgroundColorPane));
		}

		private JPanel createLabelColorPane(String paramString, ColorSelectionPane paramColorSelectionPane) {
			JPanel localJPanel = new JPanel();
			localJPanel.setLayout(new FlowLayout(1, 2, 0));
			localJPanel.add(new JLabel(paramString));
			localJPanel.add(paramColorSelectionPane);
			return localJPanel;
		}

		public void populate(Background paramBackground) {
			if ((paramBackground != null) && (paramBackground instanceof PatternBackground)) {
				PatternBackground localPatternBackground = (PatternBackground) paramBackground;
				int i = localPatternBackground.getPatternIndex();
				if ((i >= 0) && (i < this.patternButtonArray.length)) {
					this.patternButtonArray[i].setSelected(true);
					this.patternIndex = i;
				} else {
					this.patternIndex = 0;
				}
				this.foregroundColorPane.setColor(localPatternBackground.getForeground());
				this.backgroundColorPane.setColor(localPatternBackground.getBackground());
			} else {
				this.patternIndex = 0;
				this.patternButtonArray[0].setSelected(true);
				this.foregroundColorPane.setColor(Color.lightGray);
				this.backgroundColorPane.setColor(Color.black);
			}
		}

		public Background update() throws Exception {
			return new PatternBackground(this.patternIndex, this.foregroundColorPane.getColor(),
					this.backgroundColorPane.getColor());
		}

		public void addChangeListener(ChangeListener paramChangeListener) {
			this.foregroundColorPane.addColorChangeListener(paramChangeListener);
			this.backgroundColorPane.addColorChangeListener(paramChangeListener);
			for (int i = 0; i < this.patternButtonArray.length; ++i) {
				this.patternButtonArray[i].addChangeListener(paramChangeListener);
			}
		}

		class PatternButton extends JToggleButton implements ActionListener {

			private int pIndex = 0;
			private PatternBackground patternBackground;

			public PatternButton(int paramInt) {
				this.pIndex = paramInt;
				addActionListener(this);
				setCursor(new Cursor(12));
				setBorder(null);
				this.patternBackground = new PatternBackground(this.pIndex, Color.lightGray, Color.black);
			}

			public void paintComponent(Graphics paramGraphics) {
				Graphics2D localGraphics2D = (Graphics2D) paramGraphics;
				Dimension localDimension = getSize();
				this.patternBackground.paint(localGraphics2D, new Rectangle2D.Double(0.0D, 0.0D,
						localDimension.width - 1, localDimension.height - 1));
				if (this.pIndex == BackgroundPane.PatternBackgroundPane.this.patternIndex) {
					localGraphics2D.setPaint(new Color(255, 51, 0));
				} else {
					localGraphics2D.setPaint(Color.gray);
				}
				GraphHelper.draw(localGraphics2D, new Rectangle2D.Double(0.0D, 0.0D, localDimension.width - 1,
						localDimension.height - 1));
			}

			public Dimension getPreferredSize() {
				return new Dimension(24, 24);
			}

			public void setPatternForeground(Color paramColor) {
				this.patternBackground.setForeground(paramColor);
			}

			public void setPatternBackground(Color paramColor) {
				this.patternBackground.setBackground(paramColor);
			}

			public void actionPerformed(ActionEvent paramActionEvent) {
				// BackgroundPane.PatternBackgroundPane.access$502(BackgroundPane.PatternBackgroundPane.this,
				// this.pIndex);
				fireChagneListener();
				BackgroundPane.PatternBackgroundPane.this.repaint();
			}

			public void addChangeListener(ChangeListener paramChangeListener) {
				this.changeListener = paramChangeListener;
			}

			private void fireChagneListener() {
				if (this.changeListener == null) {
					return;
				}
				ChangeEvent localChangeEvent = new ChangeEvent(this);
				this.changeListener.stateChanged(localChangeEvent);
			}
		}
	}

	class TextureBackgroundPane extends BackgroundPane.BackgroundSettingPane {

		private TexturePaint texturePaint;
		private TextureButton[] textureButtonArray;

		public TextureBackgroundPane() {
			super();
			initComponents();
		}

		protected void initComponents() {
			setLayout(new BorderLayout());
			setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
			JPanel localJPanel1 = new JPanel();
			add(localJPanel1, "North");
			localJPanel1.setLayout(new BoxLayout(localJPanel1, 1));
			JPanel localJPanel2 = new JPanel();
			localJPanel1.add(localJPanel2);
			localJPanel2.setLayout(new FlowLayout(1, 2, 3));
			localJPanel2.setBorder(BorderFactory.createTitledBorder("Background-Texture"));
			JPanel localJPanel3 = new JPanel();
			localJPanel2.add(localJPanel3);
			localJPanel3.setLayout(new GridLayout(3, 8, 6, 4));
			ButtonGroup localButtonGroup = new ButtonGroup();
			this.textureButtonArray = new TextureButton[BackgroundPane.EmbedTexturePaintArray.length];
			for (int i = 0; i < BackgroundPane.EmbedTexturePaintArray.length; ++i) {
				this.textureButtonArray[i] = new TextureButton(BackgroundPane.EmbedTexturePaintArray[i],
						BackgroundPane.EmbedTexturePaintDesArray[i]);
				localButtonGroup.add(this.textureButtonArray[i]);
				localJPanel3.add(this.textureButtonArray[i]);
			}
		}

		public void populate(Background paramBackground) {
			if (paramBackground instanceof TextureBackground) {
				TextureBackground localTextureBackground = (TextureBackground) paramBackground;
				this.texturePaint = localTextureBackground.getTexturePaint();
				for (int i = 0;; ++i) {
					if (i >= this.textureButtonArray.length) {
						return;
					}
					if (!(this.textureButtonArray[i].getTexturePaint().equals(this.texturePaint))) {
						continue;
					}
					this.textureButtonArray[i].setSelected(true);
					return;
				}
			}
			this.textureButtonArray[0].setSelected(true);
			this.texturePaint = this.textureButtonArray[0].getTexturePaint();
		}

		public Background update() throws Exception {
			return new TextureBackground(this.texturePaint);
		}

		public void addChangeListener(ChangeListener paramChangeListener) {
			for (int i = 0; i < this.textureButtonArray.length; ++i) {
				this.textureButtonArray[i].addChangeListener(paramChangeListener);
			}
		}

		class TextureButton extends JToggleButton implements ActionListener {

			private TexturePaint buttonTexturePaint;

			public TextureButton(TexturePaint paramTexturePaint, String paramString) {
				this.buttonTexturePaint = paramTexturePaint;
				setToolTipText(paramString);
				setCursor(new Cursor(12));
				addActionListener(this);
				setBorder(null);
			}

			public void paintComponent(Graphics paramGraphics) {
				Graphics2D localGraphics2D = (Graphics2D) paramGraphics;
				Dimension localDimension = getSize();
				localGraphics2D.setPaint(this.buttonTexturePaint);
				GraphHelper.fill(localGraphics2D, new Rectangle2D.Double(0.0D, 0.0D, localDimension.width - 1,
						localDimension.height - 1));
				if (ComparatorUtils.equals(BackgroundPane.TextureBackgroundPane.this.texturePaint,
						this.buttonTexturePaint)) {
					localGraphics2D.setPaint(Color.black);
				} else {
					localGraphics2D.setPaint(Color.gray);
				}
				GraphHelper.draw(localGraphics2D, new Rectangle2D.Double(0.0D, 0.0D, localDimension.width - 1,
						localDimension.height - 1));
			}

			public Dimension getPreferredSize() {
				return new Dimension(36, 32);
			}

			public TexturePaint getTexturePaint() {
				return this.buttonTexturePaint;
			}

			public void actionPerformed(ActionEvent paramActionEvent) {
				// BackgroundPane.TextureBackgroundPane.access$102(BackgroundPane.TextureBackgroundPane.this,
				// getTexturePaint());
				fireChagneListener();
				BackgroundPane.TextureBackgroundPane.this.repaint();
			}

			public void addChangeListener(ChangeListener paramChangeListener) {
				this.changeListener = paramChangeListener;
			}

			private void fireChagneListener() {
				if (this.changeListener == null) {
					return;
				}
				ChangeEvent localChangeEvent = new ChangeEvent(this);
				this.changeListener.stateChanged(localChangeEvent);
			}
		}
	}

	class ColorBackgroundPane extends BackgroundPane.BackgroundSettingPane {

		private DetailColorSelectPane detailColorSelectPane;

		public ColorBackgroundPane() {
			super();
			setLayout(new BorderLayout());
			this.detailColorSelectPane = new DetailColorSelectPane();
			add(this.detailColorSelectPane, "Center");
		}

		public void populate(Background paramBackground) {
			if (paramBackground instanceof ColorBackground) {
				this.detailColorSelectPane.populate(((ColorBackground) paramBackground).getColor());
			} else {
				this.detailColorSelectPane.populate(Color.white);
			}
		}

		public Background update() throws Exception {
			return ColorBackground.getInstance(this.detailColorSelectPane.update());
		}

		public void addChangeListener(ChangeListener paramChangeListener) {
			this.detailColorSelectPane.addChangeListener(paramChangeListener);
		}
	}

	class NullBackgroundPane extends BackgroundPane.BackgroundSettingPane {

		public NullBackgroundPane() {
			super();
			setLayout(new BorderLayout());
			JLabel localJLabel = new JLabel("Background-Background_is_NULL" + "...");
			add(localJLabel);
			localJLabel.setHorizontalAlignment(0);
			// localJLabel.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor()));
		}

		public void populate(Background paramBackground) {
		}

		public Background update() throws Exception {
			return null;
		}

		public void addChangeListener(ChangeListener paramChangeListener) {
		}
	}

	abstract class BackgroundSettingPane extends JPanel {

		public abstract void populate(Background paramBackground);

		public abstract Background update() throws Exception;

		public abstract void addChangeListener(ChangeListener paramChangeListener);
	}

	public class BackgroundPreviewLabel extends JLabel {

		private Background background = null;
		private EventListenerList backgroundChangeListenerList = new EventListenerList();

		public BackgroundPreviewLabel() {
			setHorizontalAlignment(0);
		}

		public BackgroundPreviewLabel(Background paramBackground) {
			setBackgroundObject(paramBackground);
		}

		public void paintComponent(Graphics paramGraphics) {
			super.paintComponent(paramGraphics);
			if (getBackgroundObject() != null) {
				getBackgroundObject().paint((Graphics2D)paramGraphics,
						new Rectangle2D.Double(0.0D, 0.0D, getSize().getWidth(), getSize().getHeight()));
				setText("");
			} else {
				setText("Background-Background_is_NULL" + "...");
			}
		}

		public Background getBackgroundObject() {
			return this.background;
		}

		public void setBackgroundObject(Background paramBackground) {
			this.background = paramBackground;
			fireBackgroundStateChanged();
			repaint();
		}

		public void addBackgroundChangeListener(ChangeListener paramChangeListener) {
			this.backgroundChangeListenerList.add(ChangeListener.class, paramChangeListener);
		}

		public void fireBackgroundStateChanged() {
			Object[] arrayOfObject = this.backgroundChangeListenerList.getListenerList();
			ChangeEvent localChangeEvent = null;
			for (int i = arrayOfObject.length - 2; i >= 0; i -= 2) {
				if (arrayOfObject[i] != ChangeListener.class) {
					continue;
				}
				if (localChangeEvent == null) {
					localChangeEvent = new ChangeEvent(this);
				}
				((ChangeListener) arrayOfObject[(i + 1)]).stateChanged(localChangeEvent);
			}
		}
	}

	private class DetailColorSelectPane extends JPanel {

		private ColorSelectionPane colorSelectPane;
		private JLabel colorPreviewLabel;
		ChangeListener colorPreviewLabelChangeListener = new ChangeListener() {

			public void stateChanged(ChangeEvent paramChangeEvent) {
				DetailColorSelectPane.this.colorPreviewLabel.setBackground(DetailColorSelectPane.this.colorSelectPane
						.getColor());
			}
		};

		public DetailColorSelectPane() {
			setBorder(BorderFactory.createEmptyBorder(4, 4, 0, 4));
			setLayout(new BorderLayout());
			JPanel localJPanel1 = new JPanel();
			add(localJPanel1, "West");
			localJPanel1.setLayout(new BoxLayout(localJPanel1, 0));
			JPanel localJPanel2 = new JPanel();
			localJPanel1.add(localJPanel2);
			localJPanel2.setLayout(new BorderLayout());
			JLabel localJLabel = new JLabel("Color" + ":");
			localJPanel2.add(localJLabel, "North");
			localJPanel1.add(Box.createHorizontalStrut(4));
			JPanel localJPanel3 = new JPanel();
			localJPanel1.add(localJPanel3);
			localJPanel3.setLayout(new BorderLayout());
			this.colorSelectPane = new ColorSelectionPane(10);
			localJPanel3.add(this.colorSelectPane, "North");
			localJPanel1.add(Box.createHorizontalStrut(8));
			JPanel localJPanel4 = new JPanel();
			localJPanel1.add(localJPanel4);
			localJPanel4.setLayout(new BorderLayout());
			JPanel localJPanel5 = new JPanel();
			localJPanel4.add(localJPanel5, "North");
			localJPanel5.setLayout(new BorderLayout());
			this.colorPreviewLabel = new JLabel("                                        ") {

				public void paintComponent(Graphics paramGraphics) {
					super.paintComponent(paramGraphics);
					Graphics2D localGraphics2D = (Graphics2D) paramGraphics;
					localGraphics2D.setPaint(getBackground());
					GraphHelper.fill(localGraphics2D, new Rectangle2D.Double(0.0D, 0.0D, getSize().getWidth(),
							getSize().getHeight()));
				}
			};
			this.colorPreviewLabel.setFont(new Font(getFont().getFontName(), getFont().getStyle(),
					getFont().getSize() + 4));
			this.colorPreviewLabel.setBorder(BorderFactory.createEmptyBorder(0, 2, 2, 2));
			localJPanel5.add(this.colorPreviewLabel, "Center");
			localJPanel5.setBorder(BorderFactory.createTitledBorder("Preview"));
			addChangeListener(this.colorPreviewLabelChangeListener);
			populate(Color.white);
		}

		public void populate(Color paramColor) {
			this.colorSelectPane.setColor(paramColor);
		}

		public Color update() {
			return this.colorSelectPane.getColor();
		}

		public void addChangeListener(ChangeListener paramChangeListener) {
			// this.colorSelectPane.addChangeListener(paramChangeListener);
		}
	}

	public static void main(String[] args) {
		BackgroundPane pane = new BackgroundPane();
		pane.showDialog(null, "测试", 400, 300);
	}
}
